package avicit.im.lantop.archivemanager.archivearrange.arrange.action;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * <p>金航数码科技有限责任公司</p>
 * <p>作者：zhongyh</p>
 * <p>邮箱：zhongyh@avic-digital.com</p>
 * <p>创建时间： 2019-10-12 上午9:58:37 </p>
 * <p>类说明：配置文件读取</p>
 * <p>修改记录： </p>
 */
public class JProperties {

	private static Properties prop = null;
	
	private static boolean isExist = false;

	private JProperties() {
		
	}
	
	public static String getFileProperties(String key){
		ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
		if(prop == null){
			prop = new Properties();
			try{
				InputStream in = null;
				//加载文件配置
				Resource res = resourceResolver.getResource("classpath:/configuration/fileconfig.properties");
				in = res.getInputStream();
				if(in != null){
					prop.load(in);
					in.close();
					isExist = true;
				}
			} catch (IOException e) {
				e.printStackTrace();
			} 
		}
		
		if(isExist){
			if (prop.getProperty(key) != null && !"".equals(prop.getProperty(key))){
				return prop.getProperty(key).trim();
			} else {
				return "";
			}
		}
		
		return "";
	}

}
